home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.border;
-
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Graphics;
- import java.awt.Insets;
-
- public class LineBorder extends AbstractBorder {
- private static Border blackLine;
- private static Border grayLine;
- protected int thickness;
- protected Color lineColor;
- protected boolean roundedCorners;
-
- public LineBorder(Color color) {
- this(color, 1, false);
- }
-
- public LineBorder(Color color, int thickness) {
- this(color, thickness, false);
- }
-
- LineBorder(Color color, int thickness, boolean roundedCorners) {
- this.lineColor = color;
- this.thickness = thickness;
- this.roundedCorners = roundedCorners;
- }
-
- public static Border createBlackLineBorder() {
- if (blackLine == null) {
- blackLine = new LineBorder(Color.black, 1);
- }
-
- return blackLine;
- }
-
- public static Border createGrayLineBorder() {
- if (grayLine == null) {
- grayLine = new LineBorder(Color.gray, 1);
- }
-
- return grayLine;
- }
-
- public Insets getBorderInsets(Component c) {
- return new Insets(this.thickness, this.thickness, this.thickness, this.thickness);
- }
-
- public Color getLineColor() {
- return this.lineColor;
- }
-
- public int getThickness() {
- return this.thickness;
- }
-
- public boolean isBorderOpaque() {
- return true;
- }
-
- public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
- Color oldColor = g.getColor();
- g.setColor(this.lineColor);
-
- for(int i = 0; i < this.thickness; ++i) {
- if (!this.roundedCorners) {
- g.drawRect(x + i, y + i, width - i - i - 1, height - i - i - 1);
- } else {
- g.drawRoundRect(x + i, y + i, width - i - i - 1, height - i - i - 1, this.thickness, this.thickness);
- }
- }
-
- g.setColor(oldColor);
- }
- }
-